//
//  ViewController.m
//  TomCat
//
//  Created by aaaaaa on 16/6/9.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "CatImageView.h"
#import "CatUIButton.h"

@interface ViewController ()
@property (nonatomic, retain) UIImageView *imageView;
@end

@implementation ViewController

- (void)dealloc
{
    [_imageView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatBackGround];
    [self createButton];
}

- (void)creatBackGround{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"angry_00" ofType:@"jpg"];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    UIImageView *back = [[UIImageView alloc] initWithImage:image];
    back.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:back];
    [back release];
}

- (void)createButton{

    
    CatUIButton *cymble = [CatUIButton buttonWithFrame:CGRectMake(20, 370, 60, 60) withImageName:@"cymbal" withImageCount:13];
    [self.view addSubview:cymble.catImageView];
    
    CatUIButton *drink = [CatUIButton buttonWithFrame:CGRectMake(20, 370 + 60 + 40, 60, 60) withImageName:@"drink" withImageCount:81];
    [self.view addSubview:drink.catImageView];
    
    CatUIButton *eat = [CatUIButton buttonWithFrame:CGRectMake(20, 370 + 100 + 100, 60, 60) withImageName:@"eat" withImageCount:40];
    [self.view addSubview:eat.catImageView];
    
    CatUIButton *fart = [CatUIButton buttonWithFrame:CGRectMake(414 - 20 - 60, 370, 60, 60) withImageName:@"fart" withImageCount:28];
    [self.view addSubview:fart.catImageView];
    
    
    CatUIButton *pie = [CatUIButton buttonWithFrame:CGRectMake(414 - 20 - 60, 370 + 100, 60, 60) withImageName:@"pie" withImageCount:24];
    [self.view addSubview:pie.catImageView];
    
    CatUIButton *scratch = [CatUIButton buttonWithFrame:CGRectMake(414 - 20 - 60, 370 + 100 + 100, 60, 60) withImageName:@"scratch" withImageCount:56];
    [self.view addSubview:scratch.catImageView];
    
    CatUIButton *footLeft = [CatUIButton buttonNoImageWithFrame:CGRectMake(200, 630, 80, 80) withImageName:@"footLeft" withImageCount:30];
//    footLeft.backgroundColor = [UIColor redColor];
    [self.view addSubview:footLeft.catImageView];
    
    CatUIButton *footRight = [CatUIButton buttonNoImageWithFrame:CGRectMake(120, 630, 80, 80) withImageName:@"footRight" withImageCount:30];
//    footRight.backgroundColor = [UIColor greenColor];
    [self.view addSubview:footRight.catImageView];
    
    CatUIButton *angry = [CatUIButton buttonNoImageWithFrame:CGRectMake(110, 150, 200, 200) withImageName:@"angry" withImageCount:26];
//    angry.backgroundColor = [UIColor redColor];
    [self.view addSubview:angry.catImageView];
    
    CatUIButton *stomach = [CatUIButton buttonNoImageWithFrame:CGRectMake(130, 480, 150, 150) withImageName:@"stomach" withImageCount:34];
//    stomach.backgroundColor = [UIColor redColor];
    [self.view addSubview:stomach.catImageView];
    
    
    
    [self.view addSubview:cymble];
    [cymble release];
    [cymble addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:drink];
    [drink release];
    [drink addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.view addSubview:eat];
    [eat release];
    [eat addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.view addSubview:fart];
    [fart release];
    [fart addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.view addSubview:pie];
    [pie release];
    [pie addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.view addSubview:scratch];
    [scratch release];
    [scratch addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:footLeft];
    [footLeft release];
    [footLeft addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
   
    [self.view addSubview:footRight];
    [footRight release];
    [footRight addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:angry];
    [angry release];
    [angry addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:stomach];
    [stomach release];
    [stomach addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)startAction:(CatUIButton *)button
{

    if ([self.imageView isAnimating]) {
        return;
    }
    
    self.imageView = button.catImageView;
    [self.imageView startAnimating];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
